﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class TourPopular
    {
    #region
        public eTourPopular Data;
        public TourPopular()
        {
            Data = new eTourPopular();
        }
        ~TourPopular()
        { 
        }
        public virtual void Dispose()
        {
        }
        public int DeleteById(int ID)
        {
            int nResult = 0;
            cTourPopular objDAL = new cTourPopular();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public void LoadById(int ID)
        {
            cTourPopular objDAL = new cTourPopular();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }
        public DataTable GetAll()
        {
            DataTable tbResult = new DataTable();
            cTourPopular objDAL = new cTourPopular();
            tbResult = objDAL.GetAll();
            return tbResult;
        }
        public int Insert()
        {
            int nResult = 0;
            cTourPopular objInfor = new cTourPopular();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.TourPopularID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cTourPopular objInfor = new cTourPopular();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int UpdatePriority(int TourID, int Priority)
        {
            int nResult = 0;
            cTourPopular objDAL = new cTourPopular();
            try
            {
                objDAL.LoadByPrimaryKey(TourID);
                objDAL.Priority = Priority;

                objDAL.Save();
                nResult = objDAL.TourPopularID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        
        private void MappingData(cTourPopular objInfor)
        {
            objInfor.Description1 = Data.Description1;
            objInfor.Description2 = Data.Description2;
            objInfor.Description3 = Data.Description3;
            objInfor.IsHomePage = Data.IsHomePage;
            objInfor.Priority = Data.Priority;
        }
        private void ConvertData(cTourPopular objInfor)
        {
            Data.Description1 = objInfor.Description1;
            Data.Description2 = objInfor.Description2;
            Data.Description3 = objInfor.Description3;
            Data.IsHomePage = objInfor.IsHomePage;
            Data.Priority = objInfor.Priority;
        }
        public DataTable Search_IsHome()
        {
            DataTable tbResult = new DataTable();
            cTourPopular objDAL = new cTourPopular();
            tbResult = objDAL.Search_IsHome();
            return tbResult;
        }
        #endregion
    }
}
        